<?php

namespace App\Support;

use Aws\S3\S3Client;

class AwsS3
{



    public $client ;

    public function __construct()
    {
        $this->client =new S3Client([
            'region' => 'us-east-1',
            'version' => '2006-03-01',
            'endpoint' => 'https://s3.us-east-1.amazonaws.com',
            'credentials' => [
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_ACCESS_KEY_SECRET')
            ]
            // Set the S3 class to use objects.dreamhost.com/bucket
            // instead of bucket.objects.dreamhost.com
            //  'use_path_style_endpoint' => true
        ]);
    }



    public function getPresagedUrl($dir,$bucket =''){
        if(!$bucket){
            $bucket = env('AWS_BUCKET');
        }
        //Creating a presigned URL
        $cmd = $this->client->getCommand('putObject', [
            'Bucket' => $bucket,
            'Key' => $dir
        ]);

        $result = $this->client->createPresignedRequest($cmd, '+20 minutes');

        return (string)$result->getUri();
    }


}
